﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace GH.Web
{
    public partial class AjaxExist : GH.Web.BasePage.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                int count = 0;
                int unitID = 0;
                string strOldName = "";
                string id = Request["id"].ToString();
                string strName = Request["strName"].ToString();
                string strFormFlg = Request["FormFlg"].ToString();
                switch (strFormFlg)
                {
                    //  单位
                    case "Unit":
                        GH.BLL.Union bllUnion = new GH.BLL.Union();
                        if (id != "")
                        {
                            GH.BLL.Union departBLL = new GH.BLL.Union();
                            strOldName = departBLL.GetModel(Convert.ToInt32(id)).单位代码;
                        }
                        count = bllUnion.GetList(" 单位代码='" + strName + "'").Tables[0].Rows.Count;
                        if (count > 0)
                        {

                            if (strOldName == strName && count == 1)
                            {

                                Response.Write(0);
                            }
                            else
                            {
                                Response.Write("1");
                            }
                        }
                        else
                        {

                            Response.Write("0");
                        }

                        break;

                    //用户
                    case "USER":
                        GH.BLL.User bllUser = new GH.BLL.User();
                        count = bllUser.GetList("用户ID='" + strName + "'").Tables[0].Rows.Count;
                        if (count > 0)
                        {
                            Response.Write("1");
                        }
                        else
                        {
                            Response.Write("0");
                        }
                        break;
                    case "DepartMent":
                        unitID = Convert.ToInt32(Request["UnitID"]);

                        GH.BLL.DepartMent bllDepartment = new GH.BLL.DepartMent();
                        if (id != "")
                        {
                            GH.BLL.DepartMent departBLL = new GH.BLL.DepartMent();
                            strOldName = departBLL.GetModel(Convert.ToInt32(id)).部门代码;
                        }

                        count = bllDepartment.GetList(" 部门代码='" + strName + "'").Tables[0].Rows.Count;
                        if (count > 0)
                        {

                            if (strOldName == strName && count == 1)
                            {

                                Response.Write(0);
                            }
                            else
                            {
                                Response.Write("1");
                            }
                        }
                        else
                        {
                            Response.Write("0");
                        }
                        break;
                    //班组管理 WorkGroup
                    case "WorkGroup":
                        unitID = Convert.ToInt32(Request["UnitID"]);
                        GH.BLL.Group bllGroup = new GH.BLL.Group();
                        count = bllGroup.GetList(" 班组代码='" + strName + "'").Tables[0].Rows.Count;

                        if (id != "")
                        {
                            GH.BLL.Group departBLL = new GH.BLL.Group();
                            strOldName = departBLL.GetModel(Convert.ToInt32(id)).班组代码;
                        }

                        if (count > 0)
                        {

                            if (strOldName == strName && count == 1)
                            {

                                Response.Write(0);
                            }
                            else
                            {
                                Response.Write("1");
                            }
                        }
                        else
                        {
                            Response.Write("0");
                        }
                        break;
                    //角色管理  Role
                    case "Role":
                        GH.BLL.Role bllRole = new GH.BLL.Role();
                        count = bllRole.GetList(" 角色名称='" + strName + "'").Tables[0].Rows.Count;
                        if (id != "")
                        {
                            GH.BLL.Role departBLL = new GH.BLL.Role();
                            strOldName = departBLL.GetModel(Convert.ToInt32(id)).角色名称;
                        }

                        if (count > 0)
                        {

                            if (strOldName == strName && count == 1)
                            {

                                Response.Write(0);
                            }
                            else
                            {
                                Response.Write("1");
                            }
                        }
                        else
                        {
                            Response.Write("0");
                        }
                        break;
                    //疗养情况时间段存在性判断
                    case "RecuperateCondationSumirise":

                        int unionID = Convert.ToInt32(Request["UnionID"]);
                        GH.BLL.RecuperateCondation bllRecuperateCondation = new GH.BLL.RecuperateCondation();
                        string sign = bllRecuperateCondation.DateIsExtis(strName, unionID);
                        if (sign == "Null")
                        {
                            //表示不存在
                            Response.Write("0");

                        }
                        else
                        {
                            //表示不存在
                            Response.Write(sign);
                        }
                        break;


                    //疗养计划时间段存在性判断
                    case "RecuperatePlan":

                        GH.BLL.RecuperatePlan bllRecuperatePlan = new GH.BLL.RecuperatePlan();
                        string RecuperatePlansign = bllRecuperatePlan.DateIsExtis(strName);
                        if (RecuperatePlansign == "Null")
                        {
                            //表示不存在
                            Response.Write("0");

                        }
                        else
                        {
                            //表示不存在
                            Response.Write(RecuperatePlansign);
                        }
                        break;

                    //单位疗养计划时间段存在性判断
                    case "theRecuperatePlan":
                        unitID = Convert.ToInt32(Request["UnionID"]);
                        GH.BLL.RecuperatePlan thebllRecuperatePlan = new GH.BLL.RecuperatePlan();
                        string theRecuperatePlansign = thebllRecuperatePlan.DateIsExtis(unitID, strName);
                        if (theRecuperatePlansign == "Null")
                        {
                            //表示不存在
                            Response.Write("0");

                        }
                        else
                        {
                            //表示不存在
                            Response.Write(theRecuperatePlansign);
                        }
                        break;

                    //单位疗养计划时间段存在性判断
                    case "EmployMemberShipRate":
                        unitID = Convert.ToInt32(Request["UnionID"]);
                        GH.BLL.EmployMemberShipRate bllEmployMemberShipRate = new GH.BLL.EmployMemberShipRate();
                        string bllEmployMemberShipRateSign = bllEmployMemberShipRate.DateIsExtis(strName, unitID);
                        if (bllEmployMemberShipRateSign == "Null")
                        {
                            //表示不存在
                            Response.Write("0");

                        }
                        else
                        {
                            //表示存在
                            Response.Write(bllEmployMemberShipRateSign);
                        }
                        break;



                    //
                    case "MemberShipRate":
                        unitID = Convert.ToInt32(Request["UnionID"]);
                        GH.BLL.MemberShipRate bllMemberShipRate = new GH.BLL.MemberShipRate();
                        string MemberShipRateSign = bllMemberShipRate.DateIsExtis(strName, unitID);
                        if (MemberShipRateSign == "Null")
                        {
                            //表示不存在
                            Response.Write("0");

                        }
                        else
                        {
                            //表示存在
                            Response.Write(MemberShipRateSign);
                        }
                        break;

                }

            }
            catch
            {

                Response.Write("NG");
            }
            Response.End();
        }
    }
}
